home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UCRASM25.ARJ / LTOA.ASM < prev    next >
Assembly Source File  |  1991-11-14  |  2KB  |  118 lines

  1. StdGrp        group    stdlib,stddata
  2. stddata        segment    para public 'sldata'
  3. stddata        ends
  4. ;
  5. stdlib        segment    para public 'slcode'
  6.         assume    cs:stdgrp
  7. ;
  8.         extrn    sl_malloc:far
  9. ;
  10. ; Release 2.0 modifications 9/22/91, R. Hyde
  11. ; Created three versions of each routine: LTOA, LTOA2, and LTOAm
  12. ;
  13. ; LTOA-    converts the value in DX:AX to a string.  ES:DI points at the target
  14. ;    location.
  15. ;
  16. ; LTOA2-Like the routine above, except it does not preserve DI.  Leaves DI
  17. ;    pointing at the terminating zero byte.
  18. ;
  19.         public    sl_ltoa
  20. sl_ltoa        proc    far
  21.         push    di
  22.         call    far ptr sl_ltoa2
  23.         pop    di
  24.         ret
  25. sl_ltoa        endp
  26. ;
  27.         public    sl_ltoa2
  28. sl_ltoa2    proc    far
  29.         push    ax
  30.         push    dx
  31. ;
  32.         cmp    dx, 0
  33.         jge    Doit
  34.         mov    byte ptr es:[di], '-'
  35.         inc    di
  36.         neg    dx
  37.         neg    ax
  38.         sbb    dx, 0
  39. ;
  40. DoIt:        call    puti4
  41.         mov    byte ptr es:[di], 0
  42.         clc                ;Needed by sl_ltoam
  43.         pop    dx
  44.         pop    ax
  45.         ret
  46. sl_ltoa2    endp
  47. ;
  48. ;
  49. ;
  50. ; ULTOA converts the unsigned dword value in DX:AX to a string.
  51. ; ULTOA does not preserve DI, rather, it leaves DI pointing at the 0 byte.
  52. ;
  53.         public    sl_ultoa
  54. sl_ultoa    proc    far
  55.         push    di
  56.         call    far ptr sl_ultoa2
  57.         pop    di
  58.         ret
  59. sl_ultoa    endp
  60. ;
  61. ;
  62.         public    sl_ultoa2
  63. sl_ultoa2    proc    far
  64.         push    ax
  65.         push    dx
  66.         call    PutI4
  67.         clc
  68.         pop    dx
  69.         pop    ax
  70.         ret
  71. sl_ultoa2    endp
  72. ;
  73. ;
  74. ;
  75. ; PutI4- Iterative routine to actually print the value in DX:AX as an integer.
  76. ;     Suggested by terje m and david holm.
  77. ;
  78. Puti4        proc
  79.         push    bx
  80.         push    cx
  81.         push    si
  82.         mov    bx, dx
  83.         mov    si, 10
  84.         xor    cx, cx
  85.         jmp    TestBX
  86. ;
  87. Puti2Lp32:    xchg    ax, bx
  88.         xor    dx, dx
  89.         div    si
  90.         xchg    ax, bx
  91.         div    si
  92.         add    dl, '0'
  93.         push    dx
  94.         inc    cx
  95. TestBX:        or    bx, bx
  96.         jnz    Puti2Lp32
  97. ;
  98. Puti2Lp2:    xor    dx, dx
  99.         div    si
  100.         add    dl, '0'
  101.         push    dx
  102.         inc    cx
  103.         or    ax, ax
  104.         jnz    Puti2Lp2
  105. ;
  106. PrintEm:    pop    ax
  107.         stosb
  108.         loop    PrintEm
  109.         mov    byte ptr es:[di], 0
  110.         pop    si
  111.         pop    cx
  112.         pop    bx
  113.         ret
  114. Puti4        endp
  115. ;
  116. stdlib        ends
  117.         end
  118.